package xc.com.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import xc.com.course.domain.Category;
import xc.com.course.mapper.CategoryMapper;
import xc.com.course.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhuolizhong
 * @since 2021-06-03
 */
@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
  @Autowired
  private CategoryMapper categoryMapper;
    @Override
    public List<Category> findall() {
        QueryWrapper<Category> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("parentid","1");
        List<Category> categories = categoryMapper.selectList(queryWrapper);
        for (Category category : categories) {
            QueryWrapper<Category> wrapper=new QueryWrapper<>();
            wrapper.eq("parentid",category.getId());
            List<Category> selectList = categoryMapper.selectList(wrapper);
            category.setChild(selectList);
        }
        return categories;
    }
}
